/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.service.catalogue.common.rest.response;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import org.apache.camel.Exchange;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import se.sll.service.catalogue.importer.extract.VMCareGiver;

/**
 *
 * @author khaleddaham
 */
public class IdmapProcessor {

    public void getVmToHSAMap(Exchange exchange) throws JsonParseException, JsonMappingException, IOException {
        ObjectMapper mapper = new ObjectMapper();
        List<VMIdMapResponse> responses = mapper.readValue(exchange.getIn().getBody(String.class), new TypeReference<List<VMIdMapResponse>>() {
        });
        HashMap<VMCareGiver, VMIdMapResponse> VMToHSAMap = new HashMap<>();
        for(VMIdMapResponse response : responses) {
            VMCareGiver vm = new VMCareGiver();
            vm.setId(response.getVmId());
            vm.setPartId(response.getVmCareGiverPartId());
            VMToHSAMap.put(vm, response);
        }
        exchange.getIn().setBody(VMToHSAMap);
    }
}
